import { getProtocol } from "../../../api/protocol";
import { shareAppMessageSet } from "../../../utils/config";
import { dataCollection } from "../../../utils/dataCollection";
import { resultProps } from "../../../utils/type";

// d:\project\cxl-driving-training-douyin\驾培\pages\protocol\protocol.ts
Page({
  data: {
    protocolHtml: '',
    title: '',
    themeCode:''
  },
  onLoad: function (options) {
    //从本地获取当前选择的城市编码
    this.setData({
      themeCode: wx.getStorageSync('themeCode')
    })

    getProtocol(options.type as string).then((res: resultProps) => {
      console.log(res)
      this.setData({
        protocolHtml: res.result,
        title: options.type === 'PRIVACY_AGREEMENT' ? '隐私协议' : '用户协议'
      })
    })
    wx.setNavigationBarTitle({ title: options.type === 'PRIVACY_AGREEMENT' ? '隐私协议' : '用户协议' })

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return { ...shareAppMessageSet() }
  },
  onHide() {
    dataCollection.setPageMapData('leave')
  },
  onUnload() {
    dataCollection.setPageMapData('leave')
  },
  onShow() {
    dataCollection.setPageMapData('enter', '协议')
  },
})